import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
import path = require('path');

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;
  const CmdPram=JSON.parse(process.argv[2])

  config.security = {
    csrf:{
      enable:false
    }
  }

  config.cluster = {
    https:CmdPram.protocol==='https'? ({
      key: path.join(__dirname, '../app/pem/key.key'), // https 证书绝对目录
      cert: path.join(__dirname, '../app/pem/public.crt'), // https 证书绝对目录
    }):null,
  };
  config.static = {
    // prefix: '/',
    dir: [
      { prefix: '/', dir: path.join(appInfo.baseDir, 'app/public/') },
    ],
  };
  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1645950792012_5403';

  // add your egg config in here
  config.middleware = ['apiIO'];

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };
  config.cors = {
    origin: "*", // 允许所有的请求源
    allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH",
  }
  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
